﻿#Region "Copyright"

' Copyright 2007 Ben Reichelt - http://benreichelt.net
' 
' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at
' 
'     http://www.apache.org/licenses/LICENSE-2.0
' 
' Unless required by applicable law or agreed to in writing, software
' distributed under the License is distributed on an "AS IS" BASIS,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and
' limitations under the License.


#End Region

Public Class RenameAssociationTask
    Inherits BaseMetaDataTask

    Private _type As String
    Private _association As String
    Private _newName As String

    Public Sub New(ByVal type As String, ByVal associationToRename As String, ByVal newAssociationName As String, ByVal sortOrder As Integer)
        Me.Type = Type
        Me.AssociationToRename = associationToRename
        Me.NewAssociationName = newAssociationName
        Me.SortOrder = sortOrder
    End Sub

    Public Overrides Sub Execute(ByVal metaData As XmlMetaData, ByVal context As AppContext)
        MyBase.Execute(metaData, context)
        metaData.FindType(Type) _
        .Association(AssociationToRename) _
        .RenameTo(NewAssociationName)
    End Sub

    Public Overrides ReadOnly Property LogMessage() As String
        Get
            Return String.Format("Renaming Association ""{0}"" to ""{1}""", AssociationToRename, NewAssociationName)
        End Get
    End Property

    Public Property Type() As String
        Get
            Return _type
        End Get
        Protected Set(ByVal value As String)
            _type = value
        End Set
    End Property

    Public Property AssociationToRename() As String
        Get
            Return _association
        End Get
        Protected Set(ByVal value As String)
            _association = value
        End Set
    End Property

    Public Property NewAssociationName() As String
        Get
            Return _newName
        End Get
        Protected Set(ByVal value As String)
            _newName = value
        End Set
    End Property

End Class
